package com.zn.utils
{
    import flash.events.SampleDataEvent;
    import flash.external.ExternalInterface;
    import flash.media.Sound;
    import flash.net.LocalConnection;
    import flash.system.Capabilities;

    public class GlobalFunc
    {
        public function GlobalFunc()
        {
        }

        public static function get isLocal():Boolean
        {
            return Boolean(Capabilities.playerType == "Desktop" || (new LocalConnection().domain == "localhost"));
        }
		
		public static function getURL():String
		{
			return ExternalInterface.call('document.location.href.toString');
		}
		
		/**
		 *从地址栏取得地址，然后获得其中参数 
		 * @return 
		 * 
		 */		
		public static function getURLParms():Object
		{
			if(isLocal)
				return {};
			
			var obj:Object = {};
			var str:String =getURL();
			if (str)
			{
				var urlArr:Array = str.split("?");
				
				var name:String;
				var value:*;
				if(urlArr[1]!=null)
				{
					urlArr=urlArr[1].split("&");
					for (var i:int = 0; i < urlArr.length; i++)
					{
						var element:Array = urlArr[i].split("=");
						if (element.length == 2)
						{
							name = element[0];
							value = element[1];
							obj[name] = value;
						}
					}
				}
			}
			
			return obj;
		}
		
		public static function lockFPS():void
		{
			var snd:Sound=new Sound();
			snd.addEventListener(SampleDataEvent.SAMPLE_DATA, function(e:SampleDataEvent):void
			{
				e.data.position=e.data.length=4096 * 4;
			});
			snd.play();
		}
    }
}